package com.manager.devicemanager.controller;
import com.manager.devicemanager.common.DataSourceNameEnum;
import com.manager.devicemanager.common.Result;
import com.manager.devicemanager.entity.Cramtest;
import com.manager.devicemanager.vo.ComponentStatusRequestVO;
import org.springframework.util.StringUtils;
import com.manager.devicemanager.service.ICramtestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import com.manager.devicemanager.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wpf
 * @since 2025-09-25
 */
@Tag(name = "CramtestController", description = " 相关接口")
@RestController
@RequestMapping("/cramtest")
public class CramtestController {

    @Autowired
    private ICramtestService iCramtestService;



    @Operation(summary = "条件查询带分页")
    @PostMapping("/page")
    public Result<IPage<Cramtest>> page(@Parameter(description = "查询条件对象") @RequestBody  PageVO<ComponentStatusRequestVO> componentStatusRequestVOPageVO){
        ComponentStatusRequestVO componentStatusRequestVO = componentStatusRequestVOPageVO.getCondition();
        String dataSourceName = DataSourceNameEnum.ICBOARDATA.getDataSourceName()+componentStatusRequestVO.getDatasourceindex();
        IPage<Cramtest> cramtestList =iCramtestService.getPage(dataSourceName,componentStatusRequestVOPageVO);
        return Result.success(cramtestList);
    }

    @Operation(summary = "条件查询")
    @PostMapping("/list")
    public Result<List<Cramtest>> list(@Parameter(description = "Cramtest 查询条件对象") @RequestBody ComponentStatusRequestVO componentStatusRequestVO){
       try{
           String dataSourceName = DataSourceNameEnum.ICBOARDATA.getDataSourceName()+componentStatusRequestVO.getDatasourceindex();
           List<Cramtest> cramtestList =iCramtestService.getList(dataSourceName,componentStatusRequestVO);
           return Result.success(cramtestList);
       }catch (Exception e){
           e.printStackTrace();
           return Result.error("查询失败");
       }
    }
}
